axios.defaults.baseURL="http://localhost:8080"
/*===============axios拦截器========================*/
/*====前置拦截====*/
axios.interceptors.request.use(config=>{
    /*携带token*/
    let utoken = localStorage.getItem("token");
    if(utoken){
        config.headers['token']=utoken;
    }
    return config;
},error => {
    Promise.reject(error);
})

/*====后置拦截====*/
axios.interceptors.response.use(result=>{
    let data = result.data;
    if(!data.success && data.message=='noLogin'){
        localStorage.removeItem("token");
        localStorage.removeItem("loginInfo");
        location.href="login.html"
    }
    return result;
},error => {
    Promise.reject(error);
})
Vue.prototype.$http=axios
/*路由前置拦截(静态资源拦截)*/
/*所有页面都要引入let url = location.href;所有页面都会反馈该当前页面地址*/
let url = location.href;
/*根据反馈的地址来进行拦截，检索当前地址是否包含登录和主页信息*/
if(url.indexOf("register1.html")==-1&&url.indexOf("login.html")==-1&&url.indexOf("callback.html")==-1&&url.indexOf("binder.html")==-1){
    /*不包含就查询是否有登录信息*/
    let loginInfo = localStorage.getItem("loginInfo");
    if(!loginInfo){
        /*没有登陆信息就跳转到登陆页面*/
        location.href="login.html";
    }
}



/**
 * 解析url获取参数对象
 * @param url
 * @returns {{}}
 */
function parseUrlParams2Obj(url){
    //获取请求参数
    let paramStr = url.substring(url.indexOf("?")+1);//code=021FdXFa14mYlA016OGa1L3R4X0FdXFO&state=1
    let paramStrs = paramStr.split("&");//[code=021FdXFa14mYlA016OGa1L3R4X0FdXFO,state=1]
    let paramObj = {};
    for(let i=0;i<paramStrs.length;i++){
        let paramName = paramStrs[i].split("=")[0];//code
        let paramValue = paramStrs[i].split("=")[1];//021FdXFa14mYlA016OGa1L3R4X0FdXFO
        paramObj[paramName] = paramValue;
    }
    return paramObj;
}